package MeteoCal.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @authors Guttadoro, Iommazzo, Saullo
 */
@Entity
@Table(name = "receivednotification")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Receivednotification.findAll", query = "SELECT r FROM Receivednotification r"),
    @NamedQuery(name = "Receivednotification.findByIdNotification", query = "SELECT r FROM Receivednotification r WHERE r.receivednotificationPK.idNotification = :idNotification"),
    @NamedQuery(name = "Receivednotification.findByIdUser", query = "SELECT r FROM Receivednotification r WHERE r.receivednotificationPK.idUser = :idUser"),
    @NamedQuery(name = Receivednotification.findByIdNotificationAndUser, query = "SELECT r FROM Receivednotification r WHERE r.receivednotificationPK.idNotification = :idNotification and r.receivednotificationPK.idUser = :idUser"),
    @NamedQuery(name = Receivednotification.findByReadnAndUser, query = "SELECT r FROM Receivednotification r WHERE r.readn = :readn and r.receivednotificationPK.idUser = :idUser")})
public class Receivednotification implements Serializable {
    
    public static final String findByReadnAndUser = "Notification.findByReadnAndUSer";
    public static final String findByIdNotificationAndUser = "Notification.findByIdNotificationAndUser";


    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ReceivednotificationPK receivednotificationPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "readn")
    private boolean readn;
    @JoinColumn(name = "idNotification", referencedColumnName = "idNotification", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Notification notification;
    @JoinColumn(name = "idUser", referencedColumnName = "Email", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;

    public Receivednotification() {
    }

    public Receivednotification(ReceivednotificationPK receivednotificationPK) {
        this.receivednotificationPK = receivednotificationPK;
    }

    public Receivednotification(ReceivednotificationPK receivednotificationPK, boolean readn) {
        this.receivednotificationPK = receivednotificationPK;
        this.readn = readn;
    }

    public Receivednotification(String idUser, int idNotification) {
        this.receivednotificationPK = new ReceivednotificationPK(idUser, idNotification);
    }

    public ReceivednotificationPK getReceivednotificationPK() {
        return receivednotificationPK;
    }

    public void setReceivednotificationPK(ReceivednotificationPK receivednotificationPK) {
        this.receivednotificationPK = receivednotificationPK;
    }

    public boolean getReadn() {
        return readn;
    }

    public void setReadn(boolean readn) {
        this.readn = readn;
    }

    public Notification getNotification() {
        return notification;
    }

    public void setNotification(Notification notification) {
        this.notification = notification;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (receivednotificationPK != null ? receivednotificationPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Receivednotification)) {
            return false;
        }
        Receivednotification other = (Receivednotification) object;
        if ((this.receivednotificationPK == null && other.receivednotificationPK != null) || (this.receivednotificationPK != null && !this.receivednotificationPK.equals(other.receivednotificationPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "MeteoCal.entity.Receivednotification[ receivednotificationPK=" + receivednotificationPK + " ]";
    }
    
}
